// 封装获取频道数据的逻辑
import { useState , useEffect } from "react";
import { getChannelsAPI } from "@/apis/article";

function useChannel(){
  // 1.相关的逻辑
  // 存储频道列表信息
  const [channelList, setChannelList] = useState([]);

  useEffect(() => {
    // 1.封装获取频道列表的方法
    const getChannelsList = async () => {
      const res = await getChannelsAPI();
      setChannelList(res.data.channels);
    };
    // 2.调用方法
    getChannelsList();
  }, []);
  // 2.将需要用到的东西返回出去
  return {
    channelList
  }
}

export default useChannel